//
//  MessageDetailViewController.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "MessageDetailViewController.h"
#import "CustomizeProgressView.h"
#import "MessageDetailTableViewCell.h"
@interface MessageDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic ,strong)UITableView *tableView;

@property(nonatomic ,strong)NSArray *dataArray;
@end

@implementation MessageDetailViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:lClearColor] backgroundColor:lClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(51, 51, 51, 1),NSFontAttributeName:MFontWithSize(18)} enableScrollEdgeAppearance:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    [self setBackButtonIsHidden:NO];
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = rgba(245, 245, 245, 1);
    
}
- (UISwitch *)createSwitch
{
    return [[UISwitch alloc] initWithFrame:CGRectMake(lScreenWidth - 10 - 44, 0, 44, 53)];
}
#pragma mark -UITableViewDelegate,UITableViewDelegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MessageDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageDetailTableViewCell"];
    
    if (!cell)
    {
        cell = [[MessageDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"MessageDetailTableViewCell"];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
    }
    NSDictionary *dic = self.dataArray[indexPath.row];
    cell.titleLabel.text = self.title;
    if (([cell.titleLabel.text isEqualToString:@"作业消息"])) {
        cell.potLabel.hidden = YES;
        cell.arrowImg.hidden = YES;
    }else{
        cell.subTitleLabel.text = dic[@"content"];
        [cell.subTitleLabel sizeToFit];
       
    }
    cell.dateLabel.text = [MethodTool dateToStyle1WithDate:[dic[@"create_time"] doubleValue]];
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 198;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}
#pragma mark -getters and setters
-(UITableView *)tableView{
    if (!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, lTopBarHeight, lScreenWidth, lScreenHeight - lTopBarHeight) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        _tableView.bounces = NO;
        [_tableView setBackgroundColor:lClearColor];
        [_tableView setSeparatorColor:lClearColor];
        [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 0)];
        
    }
    
    return _tableView;
}
- (void)setParaObject:(NSObject *)paraObject
{
    NSDictionary *dic = (NSDictionary *)paraObject;
    self.dataArray = dic[@"msg_list"];
    self.title = dic[@"title"];
}
//-(UIButton *)finishedBtn
//{
//    if (!_finishedBtn)
//    {
//        _finishedBtn = [UIButton new];
//        _finishedBtn.frame =CGRectMake(0, 0, lScreenWidth - 20, 45);
//       
//        _finishedBtn.selected =NO;
//        [_finishedBtn setTitle:@"完成" forState:UIControlStateNormal];
//        [_finishedBtn setTitleColor:lWhiteColor forState:UIControlStateNormal];
//        [_finishedBtn.titleLabel setFont:MFontWithSize(18)];
//        [_finishedBtn addTarget:self action:@selector(finishedBtnAction) forControlEvents:UIControlEventTouchUpInside];
//        _finishedBtn.backgroundColor = lClearColor;
//        UIView *btnView =[[UIView alloc] initWithFrame:CGRectMake(10, 65, lScreenWidth - 20, 45)];
//        [btnView setAllCornersWithCornerRadius:22.5];
//        // gradient
//        CAGradientLayer *gl = [CAGradientLayer layer];
//        gl.frame = CGRectMake(0,0,lScreenWidth - 20,45);
//        gl.startPoint = CGPointMake(1, 0.5);
//        gl.endPoint = CGPointMake(0, 0.5);
//        gl.colors = @[(__bridge id)[UIColor colorWithRed:41/255.0 green:241/255.0 blue:156/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:2/255.0 green:161/255.0 blue:249/255.0 alpha:1.0].CGColor];
//        gl.locations = @[@(0), @(1.0f)];
//        [btnView.layer addSublayer:gl];
//        [btnView addSubview:self.finishedBtn];
//        [self.view addSubview:btnView];
//    }
//    
//    return _finishedBtn;
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
